﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System.Collections.Generic;
using System.Diagnostics;

namespace Xceed.Silverlight.Data
{
  [DebuggerDisplay( "FilterBy = {DebuggerDisplayString}" )]
  public sealed class OrFilterExpression : FilterExpressionOperator
  {
    #region Constructors

    public OrFilterExpression( params FilterExpressionBase[] expressions )
      : base( expressions )
    {
    }

    public OrFilterExpression( IEnumerable<FilterExpressionBase> expressions )
      : base( expressions )
    {
    }

    public OrFilterExpression()
      : base()
    {
      //Note: This constructor is there to allow XAML declaration of FilterExpressions
    }

    #endregion

    public override int GetHashCode()
    {
#if WINDOWS_PHONE
      this.Freeze();
#endif

      return base.GetHashCode();
    }

    public override bool Equals( object obj )
    {
#if WINDOWS_PHONE
      this.Freeze();
#endif

      return base.Equals( obj as OrFilterExpression );
    }

    internal override FilterExpressionBase Clone()
    {
#if WINDOWS_PHONE
      this.Freeze();
#endif

      IList<FilterExpressionBase> children = this.ChildExpressions;
      int count = children.Count;
      FilterExpressionBase[] copies = new FilterExpressionBase[ count ];

      for( int i = 0; i < count; i++ )
      {
        copies[ i ] = children[ i ].Clone();
      }

      return new OrFilterExpression( copies );
    }

    [DebuggerStepThrough]
    internal override void Accept( FilterExpressionVisitor visitor )
    {
#if WINDOWS_PHONE
      this.Freeze();
#endif

      if( visitor != null )
      {
        visitor.Visit( this );
      }
    }
  }
}
